﻿using MongoDB.Driver;
using Sustainalytics.Synchronization.Interface;
using Sustainalytics.SharedEntities.EsgResearch;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.AbstractClassesAndInterfaces;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.RPIndicatorExtendedLogic
{
    public class RPIndicatorExtendedCommand : SyncEsgCommand<RPIndicatorExtended>
    {
        private readonly IMongoCollection<RPIndicatorExtended> rpIndicatorExtendedMongoCollection;

        public RPIndicatorExtendedCommand(IMongoCollection<RPIndicatorExtended> rpIndicatorExtendedMongoCollection, ILogger logger) : base(logger)
        {
            this.rpIndicatorExtendedMongoCollection = rpIndicatorExtendedMongoCollection;
        }

        protected override async Task<DeleteResult> DeleteAssociatedRecordsAsync(IEnumerable<Guid> companiesIds, Guid? additionalDiscriminator = null)
        {
            return await rpIndicatorExtendedMongoCollection.DeleteManyAsync(x => companiesIds.Contains(x.CompanyId)).ConfigureAwait(false);
        }

        protected override async Task InsertRecordsAsync(IEnumerable<RPIndicatorExtended> entities)
        {
            await rpIndicatorExtendedMongoCollection.InsertManyAsync(entities).ConfigureAwait(false);
        }
    }
}
